package com.example.chatroom.api;

import com.example.chatroom.model.Message;
import com.example.chatroom.model.MessageMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;

@RestController
public class MessageApi {
    @Resource
    MessageMapper messageMapper;

    @GetMapping("/message")
    @ResponseBody
    public Object getMessage(int sessionId){
        List<Message> messageList=messageMapper.getMessageBySessionId(sessionId);
        //由于从数据库中查询出来的是按照时间顺序降序排列的
        //展示应该是按照时间升序排列的，需要进行逆序的操作
        //调用库函数
        Collections.reverse(messageList);
        return messageList;
    }
}
